home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / GRAPHICS / TS32 / TS32.ZIP / DIBDrawingSurface.int < prev    next >
Text File  |  1996-03-21  |  7KB  |  200 lines

  1. unit DIBDrawingSurface;
  2.  
  3. (*********************************************
  4. TDIBDrawingSurface -> TGraphicControl
  5.  
  6. Provides an interface to a Windows DIB drawing surface
  7. implemented through calls to WING32.DLL.
  8.  
  9. Properties
  10.  
  11. AutoBlank-
  12.   Set to TRUE and the DIB data will be filled with the
  13.   AutoBlankColor during each call to DIBRefresh.
  14. AutoBlankColor-
  15.   The color index that will be used to fill the DIB
  16.   if AutoBlank is TRUE.
  17. BackgroundDIB-
  18.   Point to a TDIB on the form if you want a background
  19.   image to be rendered during each call to DIBRefresh.
  20. BitmapInfo-
  21.   The TBitmapInfo structure for the DIB surface.
  22. ColorPalette-
  23.   Point this to a TColorPalette on the form to use that
  24.   palette.  If nil, whatever happens to be in the current
  25.   logical palette will be used.
  26. DIBCanvas-
  27.   A TDIBCanvas that manages the DIB surface's properties.
  28.   You can control the underlying behavior of the control
  29.   by modifying properties at design time, such as Width,
  30.   Height and Orientation.  Access to the DIB surface's
  31.   memory is through this object's Bits property.
  32. DirtyRectangle-
  33.   Set this to TRUE if the corresponding DirtyRectangle
  34.   property of a TSpriteEngine is TRUE also.  It causes the
  35.   background of the surface to totally render ONLY when the
  36.   Force flag is TRUE.
  37. FillSurface-
  38.   Fill the surface with the specified color.
  39. ForceRefresh-
  40.   Set this to TRUE when the entire surface must be rendered
  41.   from scratch.  This is automatically set to TRUE during the
  42.   paint method.  It is set to FALSE at the end of each call
  43.   to DIBRefresh.
  44. GDICanvas-
  45.   The GDI canvas associated with this DIB surface.  GDI
  46.   calls can be made using the handle of this Canvas, but
  47.   if this is to be done, be sure to call SelectPalette
  48.   and RealizePalette for proper color rendering.
  49. OffsetX,OffsetY-
  50.   The offset of the control's logical coordinate system.
  51.   All sprite positions are based on the logical coord system.
  52. Palette-
  53.   The logical palette being used by this DIB.
  54. PaletteEntryFlag-
  55.   Reccommned to leave at pcNoCollapse.
  56. PhysicalWidth,PhysicalHeight-
  57.   Return the dimensions of the underling DIBCanvas.
  58. WrapHorizontal,WrapVertical
  59.   Controls whether sprites wrap around when they leave the
  60.   edge of the area.
  61.  
  62. Events
  63.  
  64. OnCustomPaint-
  65.   Gets triggered after the rendering of the background
  66.   but before the surface is actually blitted to the screen.
  67.   This is the hook where the sprite engine processing
  68.   should occur.
  69.  
  70. Methods
  71.  
  72. DIBRefresh-
  73.   Call this to blast the DIB data to the screen.  Usually
  74.   this call is placed in a HiResTimer event.
  75. *********************************************)
  76.  
  77. interface
  78.  
  79. uses
  80.   Windows, SysUtils, Messages, Classes, Graphics, Controls,
  81.   Forms, Dialogs, DIB, ExtCtrls, Grafix, ColorPalette,
  82.   DIBCanvas, DsgnIntf, ColorIndexEditor;
  83.  
  84. type
  85.  
  86.   TDIBDrawingSurface = class;
  87.  
  88. (***************************************************
  89. This record represents a TBitmapInfo record with a
  90. 256 color palette
  91. ***************************************************)
  92.   TBM = record
  93.      bminfo: TBitmapInfo;
  94.      bmiColors: array[1..256] of TRGBQuad;
  95.   end;
  96.  
  97.   TPaletteEntryFlag = ( pcNoCollapse, pcReserved );
  98.   EDIBDrawingSurface = class( Exception );
  99.  
  100.   TDIBDrawingCanvas = class( TDIBCanvas )
  101.   private
  102.      dds: TDIBDrawingSurface;
  103.   protected
  104.      procedure SetWidth( n: integer ); override;
  105.      procedure SetHeight( n: integer ); override;
  106.   public
  107.   published
  108.   end;
  109.  
  110.   TDIBDrawingSurface = class( TGraphicControl )
  111.   private
  112.      nDummy: integer;
  113.      FDIBCanvas: TDIBDrawingCanvas;
  114.      procedure CreateDIBBitmap;
  115.      procedure SetCoords( X, Y: integer );
  116.      procedure SetBoundsRect;
  117.   protected
  118.      bCreated: boolean;            { Has the WinGBitmap been created? }
  119.      bm: TBM;                      { 256 color TBitmapInfo record }
  120.      dcWindow: HDC;
  121.      FAuto: boolean;
  122.      FAutoColor: byte;
  123.      FBackDIB: TDIB;
  124.      FFlag: TPaletteEntryFlag;
  125.      FFlag_: byte;
  126.      FColorPalette: TColorPalette;
  127.      FOffX, FOffY: integer;
  128.      FWrapHorz, FWrapVert: boolean;
  129.      hDIBBitmap: HBitmap;
  130.      hDIBDC: HDC;                  { WinG device context }
  131.      hLogPalette: HPalette;        { Logical palette }
  132.      hOldBitmap: HBitmap;
  133.      hwndParent: HWND;
  134.      nWidth, nHeight: integer;
  135.      nSize: integer;
  136.      pbminfo: PBitmapInfo;         { Points to the bm record }
  137.      ppal: PLogPalette;            { Pointer to logical palette }
  138.      pSurfaceBits: pointer;        { Access to Pixels as pointer }
  139.      rectBounds: TRect;
  140.      X_, Y_: integer;              { Store the translated mouse coords }
  141.      FCanvas: TCanvas;
  142.      FPhysicalWidth, FPhysicalHeight: integer;
  143.      FOnCustomPaint: TNotifyEvent;
  144.      FForce: boolean;
  145.      FDirty: boolean;
  146.      procedure CreateDIBPalette;
  147.      procedure CreateIdentPalette;
  148.      function GetBitmapInfo: TBitmapInfo;
  149.      function GetCanvas: TCanvas;
  150.      procedure PaintHook1; dynamic;
  151.      procedure SetDIBCanvas( dc: TDIBDrawingCanvas );
  152.      procedure SetBounds( ALeft, ATop, AWidth, AHeight: Integer ); override;
  153.      procedure SetFlag( f: TPaletteEntryFlag );
  154.      procedure SetBackDIB( dib: TDIB );
  155.      procedure MouseMove( Shift: TShiftState; X, Y: integer ); override;
  156.      procedure MouseDown( Button: TMouseButton; Shift: TShiftState; X, Y: integer ); override;
  157.      procedure MouseUp( Button: TMouseButton; Shift: TShiftState; X, Y: integer ); override;
  158.      procedure Notification( AComponent: TComponent; Operation: TOperation ); override;
  159.      procedure Paint; override;
  160.   public
  161.      constructor Create( AOwner: TComponent ); override;
  162.      destructor Destroy; override;
  163.      procedure DIBRefresh;
  164.      procedure FillSurface( n: byte );
  165.      procedure RenderBackgroundDIB( dib: TDIB );
  166.      property BitmapInfo: TBitmapInfo read GetBitmapInfo;
  167.      property GDICanvas: TCanvas read FCanvas;
  168.      property ForceRefresh: boolean read FForce write FForce;
  169.      property Palette: HPalette read hLogPalette;
  170.      property PhysicalWidth: integer read FPhysicalWidth;
  171.      property PhysicalHeight: integer read FPhysicalHeight;
  172.   published
  173.      property AutoBlank: boolean read FAuto write FAuto;
  174.      property AutoBlankColor: byte read FAutoColor write FAutoColor;
  175.      property BackgroundDIB: TDIB read FBackDIB write SetBackDIB;
  176.      property DirtyRectangle: boolean read FDirty write FDirty;
  177.      property OffsetX: integer read FOffX write FOffX;
  178.      property OffsetY: integer read FOffY write FOffY;
  179.      property OnClick;
  180.      property OnDblClick;
  181.      property OnMouseMove;
  182.      property OnMouseDown;
  183.      property OnMouseUp;
  184.      property ColorPalette: TColorPalette read FColorPalette write FColorPalette;
  185.      property DIBCanvas: TDIBDrawingCanvas read FDIBCanvas write SetDIBCanvas;
  186.      property PaletteEntryFlag: TPaletteEntryFlag read FFlag write SetFlag;
  187.      property WrapHorizontal: boolean read FWrapHorz write FWrapHorz;
  188.      property WrapVertical: boolean read FWrapVert write FWrapVert;
  189.      property OnCustomPaint: TNotifyEvent read FOnCustomPaint write FOnCustomPaint;
  190.   end;
  191.  
  192.   TColorIndexEditor = class( TIntegerProperty )
  193.   private
  194.   protected
  195.   public
  196.      procedure Edit; override;
  197.      function GetAttributes: TPropertyAttributes; override;
  198.   end;
  199.  
  200. procedure Register;